<template>
  <div>
    <Search @SearchBtn="SearchBtnFn" />
    <Table
      :table-data="tableData"
      :btn-text="'新增仓库'"
      :pagecount="pagecount"
      @TypeChange="TypeChangeFn"
      @TopBtn="TopBtnFn"
      @CurrentChange="CurrentChangeFn"
      @SizeChange="SizeChangeFn"
      @OneBtn="OneBtnFn"
    />
    <DiaLog :warehouse-dialog="WarehouseDialog" :title="`确定${type.status}`" @CloseFn="CloseFn">
      <template #conent>
        <el-divider />
        <div class="conentText">
          确定要{{ type.status }}：{{ type.name }} 吗？
        </div>
      </template>
      <template #Btns>
        <div class="Btns">
          <el-button type="warning" @click="submit">确定</el-button>
          <el-button type="warning" @click="WarehouseDialog = false">取消</el-button>
        </div>
      </template>
    </DiaLog>
  </div>
</template>

<script>
import { GetManageBaseInfoList, ModifyManageBaseInfoList } from '@/api'
export default {
  data() {
    return {
      WarehouseDialog: false,
      tableData: [],
      pageS: {
        like_code: '',
        like_name: '',
        current: 1,
        size: 10,
        descs: 'createTime'
      },
      pagecount: {},
      CKtype: {
        ZZ: '中转仓',
        JG: '加工仓',
        CB: '储备仓',
        LC: '冷藏仓'
      },
      type: {}
    }
  },
  created() {
    this.ManageBaseInfoRQ()
  },
  methods: {
    // 渲染列表
    async ManageBaseInfoRQ() {
      const res = await GetManageBaseInfoList(this.pageS)
      res.data.data.records.forEach((item) => {
        item.type = this.CKtype[item.type]
        item.status = this.$store.state.PublicData.status[item.status]
      })
      this.tableData = res.data.data.records
      this.pagecount = res.data.data
    },
    // 搜索
    SearchBtnFn(data) {
      this.pageS.like_code = data.innerCooder
      this.pageS.like_name = data.name
      if (data.state === 2) {
        this.ManageBaseInfoRQ()
        return
      }
      this.pageS.status = data.state
      this.ManageBaseInfoRQ()
    },
    // 改变类型
    TypeChangeFn(type) {
      this.WarehouseDialog = true
      this.type = type
      console.log(this.type)
    },
    async submit() {
      if (this.type.status) {
        this.type.status = 0
        await ModifyManageBaseInfoList(this.type)
        return
      }
      if (!this.type.status) {
        this.type.status = 1
        await this.ModifyManageBaseInfoList(this.type)
        return
      }
    },
    // 关闭弹窗
    CloseFn() {
      this.WarehouseDialog = false
    },
    // 新建按钮
    TopBtnFn(row) {
      console.log(row)
      this.$router.push({
        name: 'details',
        params: {
          Data: this.$route.meta
        }
      })
    },
    // 编辑按钮
    OneBtnFn(row) {
      this.$router.push({
        name: 'details',
        params: {
          Id: row.id
        }
      })
    },
    // 页数跳转
    CurrentChangeFn(val) {
      this.pageS.current = val
      this.ManageBaseInfoRQ()
      console.log(val)
    },
    SizeChangeFn(val) {
      this.pageS.size = val
      this.ManageBaseInfoRQ()
    }
  }
}
</script>
<style lang="scss" scoped>
.conentText{
  margin:20px;
}
.Btns{
  width: 100%;
  display: flex;
  flex-direction: row-reverse;
}
</style>
